package ink.metoo.gude.util

import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
import org.springframework.stereotype.Component

@Component
object JsonUtils {

    private var JSON = ObjectMapper()
    private var log = logger()

    @Autowired
    fun setObjectMapper(builder: Jackson2ObjectMapperBuilder) {
        JSON = builder.createXmlMapper(false)
            .build()
        log.debug("Use Spring Jackson2ObjectMapperBuilder")
    }


    fun toJson(obj: Any?): String = JSON.writeValueAsString(obj)

}